package com.xyh.cglib;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @Author:kyle
 * @Date:2020/12/11 - 14:17
 * @Project:spring_demo1
 * @Package:com.xyh.cglib
 * @Version:1.0
 */
public class MyInterceptor implements MethodInterceptor {

    private  Object object;

    public MyInterceptor() {
    }

    public MyInterceptor(Object object) {
        this.object = object;
    }

    public Object intercept(Object o, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
        System.out.println("cglib 动态代理开始...");
//        Object invoke = method.invoke(this.object, args);
        Object invoke = methodProxy.invokeSuper(o, args);
        System.out.println("cglib 动态代理结束...");
        return invoke;
    }
}
